﻿namespace EFS.RC.CC.Deployment.Tables.Tools
{
	public static class Skills
	{
		/// GetAll
		public static EFS.RC.CC.Deployment.Entities.Skill[] GetByAll()
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.Deployment.Entities.Skill>(
					"[dbo].[Skills_GetAll]", 
					null, 
					EFS.RC.CC.Deployment.Tables.DataRow.Skill.Load);
			}
		}

		/// GetByID
		public static EFS.RC.CC.Deployment.Entities.Skill GetByID(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteRowReaderQuery<EFS.RC.CC.Deployment.Entities.Skill>(
					"[dbo].[Skills_GetByID]", 
					new EFS.DB.Parameters.Array("id", id), 
					EFS.RC.CC.Deployment.Tables.DataRow.Skill.Load);
			}
		}

		/// Create
		public static System.Int32? Create(
			System.String name)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// make params
				EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
					new System.String[] { "name", "id" },
					new System.Object[] { name, default(System.Int32) },
					new System.Boolean[] { false, true });

				// ok
				connection.DoExecuteNonQuery("[dbo].[Skills_Create]", parametersArray);

				// get id vaoue
				return parametersArray.GetOutPrameterValue<System.Int32?>("id");
			}
		}

		/// Update
		public static void Update(
			System.Int32 id,
			System.String name)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				connection.DoExecuteNonQuery(
					"[dbo].[Skills_Update]",
					new EFS.DB.Parameters.Array(
						new System.String[] { "id", "name" },
						new System.Object[] { id, name }));
			}
		}

		/// Delete
		public static void Delete(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				connection.DoExecuteNonQuery("[dbo].[Skills_Delete]", new EFS.DB.Parameters.Array("id", id));
			}
		}
	}

}